home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / games / nhak_src.zip / IOCTL.C < prev    next >
C/C++ Source or Header  |  1993-03-16  |  2KB  |  94 lines

  1. /*    SCCS Id: @(#)ioctl.c    2.0    87/09/18
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. /* This cannot be part of hack.tty.c (as it was earlier) since on some
  6.    systems (e.g. MUNIX) the include files <termio.h> and <sgtty.h>
  7.    define the same constants, and the C preprocessor complains. */
  8.  
  9. #ifndef VMS
  10. /* block some unused #defines to avoid overloading some cpp's */
  11. #define MONATTK_H
  12. #define MONFLAG_H
  13. #include "hack.h"
  14.  
  15. #if defined(BSD) || defined(ULTRIX) || defined(HPUX)
  16. # ifdef HPUX
  17. #include    <bsdtty.h>
  18. # else
  19. #include    <sgtty.h>
  20. # endif
  21. struct ltchars ltchars;
  22. struct ltchars ltchars0 = { -1, -1, -1, -1, -1, -1 }; /* turn all off */
  23. #else
  24. #include    <termio.h>    /* also includes part of <sgtty.h> */
  25. struct termio termio;
  26. # ifdef AMIX
  27. #include <sys/ioctl.h>
  28. # endif /* AMIX */
  29. #endif
  30.  
  31. void
  32. getioctls() {
  33. #if defined(BSD) || defined(ULTRIX) || defined(HPUX)
  34.     (void) ioctl(fileno(stdin), (int) TIOCGLTC, (char *) <chars);
  35.     (void) ioctl(fileno(stdin), (int) TIOCSLTC, (char *) <chars0);
  36. #else
  37.     (void) ioctl(fileno(stdin), (int) TCGETA, &termio);
  38. #endif
  39. #if defined(TIOCGWINSZ) && (defined(BSD) || defined(ULTRIX))
  40.     {
  41.         /*
  42.          * ttysize is found on Suns and BSD
  43.          * winsize is found on Suns, BSD, and Ultrix
  44.          */
  45.         struct winsize ttsz;
  46.  
  47.         if (ioctl(fileno(stdin), (int)TIOCGWINSZ, (char *)&ttsz) != -1)
  48.           {
  49.             /*
  50.              * Use the kernel's values for lines and columns if it has
  51.              * any idea.
  52.              */
  53.             if (ttsz.ws_row)
  54.               LI = ttsz.ws_row;
  55.             if (ttsz.ws_col)
  56.               CO = ttsz.ws_col;
  57.           }
  58.     }
  59. #endif
  60. }
  61.  
  62. void
  63. setioctls() {
  64. #if defined(BSD) || defined(ULTRIX) || defined(HPUX)
  65.     (void) ioctl(fileno(stdin), (int) TIOCSLTC, (char *) <chars);
  66. #else
  67.     /* Now modified to run under Sys V R3.    - may have to be #ifdef'ed */
  68.     (void) ioctl(fileno(stdin), (int) TCSETAW, &termio);
  69. #endif
  70. }
  71.  
  72. #ifdef SUSPEND        /* implies BSD */
  73. int
  74. dosuspend() {
  75. #include    <signal.h>
  76. #ifdef SIGTSTP
  77.     if(signal(SIGTSTP, SIG_IGN) == SIG_DFL) {
  78.         settty(NULL);
  79.         (void) signal(SIGTSTP, SIG_DFL);
  80.         (void) kill(0, SIGTSTP);
  81.         gettty();
  82.         setftty();
  83.         docrt();
  84.     } else {
  85.         pline("I don't think your shell has job control.");
  86.     }
  87. #else
  88.     pline("Sorry, it seems we have no SIGTSTP here.  Try ! or S.");
  89. #endif
  90.     return(0);
  91. }
  92. #endif /* SUSPEND /**/
  93. #endif /*VMS*/
  94.